package com.moli.iov.open.service.impl;

import com.moli.iov.model.dto.req.PageExtend;
import com.moli.iov.open.model.vo.req.RoleVo;
import com.moli.iov.open.service.IRoleFacadeService;
import com.moli.iov.rest.RestResponse;
import com.moli.iov.sys.model.dto.req.RoleDto;
import com.moli.iov.sys.model.dto.req.RolePermissionDto;
import com.moli.iov.sys.model.po.Role;
import com.moli.iov.sys.remote.IRoleThirdRemoteService;
import com.moli.iov.util.CommonUtils;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色业务
 * </p>
 *
 * @author zql
 * @since 2019/9/21 15:48
 */
@Slf4j
@Service
public class RoleFacadeServiceImpl implements IRoleFacadeService {

  @Reference(group = "${service.group}", check = false)
  private IRoleThirdRemoteService roleThirdRemoteService;

  /**
   *
   * 查询角色列表--下拉框
   *
   * @param roleVo
   * @return
   */
  @Override
  public RestResponse<List<Role>> listRole(RoleVo roleVo) {
    return roleThirdRemoteService.listRole(convert(roleVo));
  }

  /**
   *
   * 分页查询角色列表
   *
   * @param roleVo
   * @return
   */
  @Override
  public RestResponse<PageExtend<Role>> listRoleOfPage(RoleVo roleVo) {
    return roleThirdRemoteService.listRoleOfPage(convert(roleVo));
  }

  /**
   * 增加角色
   * @param roleVo
   * @return
   */
  @Override
  public RestResponse saveRole(RoleVo roleVo) {
    return roleThirdRemoteService.saveRole(convert(roleVo));
  }

  /**
   * 修改角色
   * @param roleVo
   * @return
   */
  @Override
  public RestResponse updateRoleByRoleId(RoleVo roleVo) {
    return roleThirdRemoteService.updateRoleByRoleId(convert(roleVo));
  }

  /**
   * 设置权限
   * @param roleVo
   * @return
   */
  @Override
  public RestResponse setPermission(RoleVo roleVo) {
    return roleThirdRemoteService.setPermission(convert(roleVo));
  }

  /**
   * 权限详情
   * @param roleVo
   * @return
   */
  @Override
  public RestResponse<RolePermissionDto> getRolePermissions(RoleVo roleVo) {
    return roleThirdRemoteService.getRolePermissions(convert(roleVo));
  }

  /**
   * 查询角色数量
   * @param roleVo
   * @return
   */
  @Override
  public RestResponse<Integer> getRoleCount(RoleVo roleVo) {
    return roleThirdRemoteService.getRoleCount(convert(roleVo));
  }

  /**
   * 转换
   * @param roleVo
   * @return
   */
  private RoleDto convert(RoleVo roleVo){
    RoleDto roleDto = new RoleDto();
    CommonUtils.copyProperties(roleVo, roleDto);
    return roleDto;
  }
}
